package com.sxm.yiwei.adapters;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.sxm.yiwei.R;
import com.sxm.yiwei.activitis.BaseActivity;
import com.sxm.yiwei.activitis.MsgMsgActivity;
import com.sxm.yiwei.beans.SqBean;
import com.sxm.yiwei.tools.CastTime;

import java.util.List;

/**
 * Created by KuKa on 2017/8/1.
 * 信息列表
 */

public class MsgListAdapter extends BaseAdapter {
    Context context;
    List<SqBean> data;
    public MsgListAdapter(Context context,  List<SqBean> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        ViewHolder holder;
        if (convertView==null){
            view = View.inflate(context, R.layout.msg_item,null);
            holder = new ViewHolder();
            holder.message = (TextView) view.findViewById(R.id.msgitem_message);
            holder.msg = (TextView) view.findViewById(R.id.msgitem_msg);
            holder.time = (TextView) view.findViewById(R.id.msgitem_time);
            view.setTag(holder);
        }else {
            view = convertView;
            holder = (ViewHolder) view.getTag();
        }
        holder.msg.setText(data.get(position).getTilte());
        holder.time.setText(CastTime.CastTime(Long.valueOf(data.get(position).getTime())));
        notifyDataSetChanged();
        return view;
    }
    class ViewHolder{

        TextView msg,time,message;
    }
}
